package cdu.notFound.controller;


import cdu.notFound.model.User;
import cdu.notFound.service.CollectService;
import cdu.notFound.service.impl.CollectServiceImpl;
import cdu.notFound.utils.LoginVerify;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 移除收藏夹
 */
@WebServlet("/RemoveCollectServlet")
public class RemoveCollectServlet extends HttpServlet {

	//从收藏夹移除一个物品
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Integer goodsId = Integer.parseInt(request.getParameter("goodsid"));
		if (LoginVerify.isLogin(request)) {
    		User loginUser = (User)request.getSession().getAttribute("loginUser");
    		int loginUserId = loginUser.getId();
			CollectService collectService = new CollectServiceImpl();
    		if(collectService.removeOneFromCollect(goodsId, loginUserId)){
    			response.getWriter().print("success");
    		}else{
    			response.getWriter().print("false");
    		}
        }else{
        	response.getWriter().print("false");
        }   
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
